# The module Element, includes all the page elements (icons, links, buttons,
# text_fields, checkboxes, select lists, dialog-boxes)
#require 'watir'

module Element
  
    class QuickCreateAccount
        #quick create link
        def self.account_name_text_field
            return $ie.text_field(:id,$popform+".Name")
        end
        def self.operating_unit_name_select_list
            return $ie.select_list(:id,$popform+".ZPick_28")
        end
        def self.operating_unit_id_select_list
            return $ie.select_list(:id,$popform+".ZPick_30")
        end
        def self.market_1_select_list
            return $ie.select_list(:id,$popform+".Indexed Pick 0")
        end
        def self.sub_market_1_select_list
            return $ie.select_list(:id,$popform+".Indexed Pick 1")
        end
        def self.market_priority_1_select_list
            return $ie.select_list(:id,$popform+".ZPick_12")
        end
        def self.market_status_1_select_list
            return $ie.select_list(:id,$popform+".ZPick_20")
        end
        #Address Information(additional)
        def self.bill_to_country_select_list
            return $ie.select_list(:id,$popform+".Parent Bill To Address.Bill To Country")
        end
        def self.bill_to_number_street_text_field
            return $ie.text_field(:id,$popform+".Parent Bill To Address.Bill To Street Address")
        end
        def self.bill_to_address_2_text_field
            return $ie.text_field(:id,$popform+".Parent Bill To Address.Bill To Street Address 2")
        end
        def self.bill_to_city_text_field
            return $ie.text_field(:id,$popform+".Parent Bill To Address.Bill To City")
        end
        def self.bill_to_county_text_field
            return $ie.text_field(:id,$popform+".Parent Bill To Address.Bill To County")
        end
        def self.bill_to_state_select_list
            return $ie.select_list(:id,$popform+".Parent Bill To Address.Bill To State")
        end
        def self.bill_to_province_text_field
            return $ie.text_field(:id,$popform+".Parent Bill To Address.Bill To Province")
        end
        def self.bill_to_post_code_text_field
            return $ie.text_field(:id,$popform+".Parent Bill To Address.Bill To Postal Code")
        end
        def self.bill_to_zip_text_field
            i = 1
            while $ie.text_field(:id => $popform+".Parent Bill To Address.Bill To Postal Code", :index =>i).disabled?
                i += 1
            end
            return $ie.text_field(:id => $popform+".Parent Bill To Address.Bill To Postal Code", :index =>i)

        end
        def self.same_as_billing_checkbox
            return $ie.checkbox(:id,$popform+".ZBool_1_VP123456")
        end
        def self.save_button
            return $ie.button(:id,"SaveID")
        end
    end
    class HudPanel_Accounts
        def self.hudpanel
            return $ie.div(:id,"hudPanel")
        end
        def self.top_link
            return hudpanel.link(:text,"Top")
        end
        def self.sub_accounts_link
            return hudpanel.link(:text,"Sub-Accounts")
        end
        def self.contacts_link
            return hudpanel.link(:text,"Contacts")
        end
        def self.install_base_link
            return hudpanel.link(:text,"Install Base")
        end
        def self.leads_link
            return hudpanel.link(:text,"Leads")
        end
        def self.opp_link
            return hudpanel.link(:text,"Opportunities")
        end
        def self.sr_link
            return hudpanel.link(:text,"Service Requests")
        end
        def self.project_link
            return hudpanel.link(:text,"Projects")
        end
        def self.product_information_link
            return hudpanle.link(:text,"Product Information")
        end
        def self.quotes_link
            return hudpanel.link(:text,"Quotes")
        end


    end
    class FrmSearch_Accounts
        @@form2="frmSearch.searchCriteria"
        def self.ctrlname_select_list
            return $ie.select_list(:id,@@form2 + ".CtrlName1")
        end
        def self.condition_select_list
            return $ie.select_list(:id,@@form2 + ".Condition1")
        end
        def self.condition_value_text_field
            return $ie.text_field(:id,@@form2 + ".Condition Value1")
        end
        def self.go_button
            return $ie.button(:id,"QuickFilterGo")
        end
        def self.selection(n)
            return $ie.link(:text=>"Select",:index=>n)
        end
        def self.account_selection(name)
            $ie = Watir::IE.attach(:title,/Search/)
            Element::FrmSearch_Accounts.condition_value_text_field.set(name)
            sleep 5
            Element::FrmSearch_Accounts.go_button.click
            sleep 5
            count = 0
            for i in 1..100
                if Element::FrmSearch_Accounts.selection(i).exist?
                    count+=1
                    i+=1
                else
                    break
                    return count
                end
            end
            return rand(count)+1
        end
    end
    class CreateAccount
        @@form1="AccountEditForm"
        def self.account_name_text_field
            return $ie.text_field(:id,@@form1+".Name")
        end
        def self.operating_unit_name_select_list
            return $ie.select_list(:id,@@form1+".ZPick_28")
        end
        def self.operating_unit_id_select_list
            return $ie.select_list(:id,@@form1+".ZPick_30")
        end
        def self.market_1_select_list
            return $ie.select_list(:id,@@form1+".Indexed Pick 0")
        end
        def self.sub_market_1_select_list
            return $ie.select_list(:id,@@form1+".Indexed Pick 1")
        end
        def self.market_priority_1_select_list
            return $ie.select_list(:id,@@form1+".ZPick_12")
        end
        def self.market_status_1_select_list
            return $ie.select_list(:id,@@form1+".ZPick_20")
        end
        #Address Information(additional)
        def self.bill_to_country_select_list
            return $ie.select_list(:id,@@form1+".Parent Bill To Address.Bill To Country")
        end
        def self.bill_to_number_street_text_field
            return $ie.text_field(:id,@@form1+".Parent Bill To Address.Bill To Street Address")
        end
        def self.bill_to_address_2_text_field
            return $ie.text_field(:id,@@form1+".Parent Bill To Address.Bill To Street Address 2")
        end
        def self.bill_to_city_text_field
            return $ie.text_field(:id,@@form1+".Parent Bill To Address.Bill To City")
        end
        def self.bill_to_county_text_field
            return $ie.text_field(:id,@@form1+".Parent Bill To Address.Bill To County")
        end
        def self.bill_to_state_select_list
            return $ie.select_list(:id,@@form1+".Parent Bill To Address.Bill To State")
        end
        def self.bill_to_province_text_field
            return $ie.text_field(:id,@@form1+".Parent Bill To Address.Bill To Province")
        end
        def self.bill_to_post_code_text_field
            return $ie.text_field(:id,@@form1+".Parent Bill To Address.Bill To Postal Code")
        end
        def self.bill_to_zip_text_field
            i = 1
            while $ie.text_field(:id => @@form1+".Parent Bill To Address.Bill To Postal Code", :index =>i).disabled?
                i += 1
            end
            return $ie.text_field(:id => @@form1+".Parent Bill To Address.Bill To Postal Code", :index =>i)

        end
        def self.same_as_billing_checkbox
            return $ie.checkbox(:id,@@form1+".ZBool_1_VP123456")
        end
        def self.save_button
            return $ie.table(:class=>"tb",:id=>"FormTitleBar").cell(:class=>"buttonTD",:index=>1)
        end
    end
    class AccountHomePage
        def self.newlist_button
            return $ie.div(:class=>"hpa",:index=>1).cell(:class,"buttonTD")
        end
        def self.newaccount_button
            return $ie.div(:class=>"hpa",:index=>2).cell(:class,"buttonTD")
        end
        def self.newtask_button
            return $ie.div(:class=>"hpa",:index=>3).cell(:class,"buttonTD")
        end

    end
    class AccountDetailPage
        @@form3="A0.R0"
        def self.newaccount_button
            return $ie.button(:text,"New")
        end
        def self.editaccount_button
            return $ie.button(:text,"Edit")
        end
        def self.copyaccount_button
            return $ie.button(:text,"Copy")
        end
        def self.deleteaccount_button
            return $ie.button(:text,"Delete")
        end
        def self.mergeaccount_button
            return $ie.button(:text,"Merge")
        end
        def self.account_name_text_field
            return $ie.text_field(:id,@@form3+".Name")
        end
        def self.operating_unit_name_select_list
            return $ie.select_list(:id,@@form3+".ZPick_28")
        end
        def self.operating_unit_id_select_list
            return $ie.select_list(:id,@@form3+".ZPick_30")
        end
        def self.market_1_select_list
            return $ie.select_list(:id,@@form3+".Indexed Pick 0")
        end
        def self.sub_market_1_select_list
            return $ie.select_list(:id,@@form3+".Indexed Pick 1")
        end
        def self.market_priority_1_select_list
            return $ie.select_list(:id,@@form3+".ZPick_12")
        end
        def self.market_status_1_select_list
            return $ie.select_list(:id,@@form3+".ZPick_20")
        end
        #Address Information(additional)
        def self.bill_to_country_select_list
            return $ie.select_list(:id,@@form3+".Parent Bill To Address.Bill To Country")
        end
        def self.bill_to_number_street_text_field
            return $ie.text_field(:id,@@form3+".Parent Bill To Address.Bill To Street Address")
        end
        def self.bill_to_address_2_text_field
            return $ie.text_field(:id,@@form3+".Parent Bill To Address.Bill To Street Address 2")
        end
        def self.bill_to_city_text_field
            return $ie.text_field(:id,@@form3+".Parent Bill To Address.Bill To City")
        end
        def self.bill_to_county_text_field
            return $ie.text_field(:id,@@form3+".Parent Bill To Address.Bill To County")
        end
        def self.bill_to_state_select_list
            return $ie.select_list(:id,@@form3+".Parent Bill To Address.Bill To State")
        end
        def self.bill_to_province_text_field
            return $ie.text_field(:id,@@form3+".Parent Bill To Address.Bill To Province")
        end
        def self.bill_to_post_code_text_field
            return $ie.text_field(:id,@@form3+".Parent Bill To Address.Bill To Postal Code")
        end
        def self.bill_to_zip_text_field
            i = 1
            while $ie.text_field(:id => @@form3+".Parent Bill To Address.Bill To Postal Code", :index =>i).disabled?
                i += 1
            end
            return $ie.text_field(:id => @@form3+".Parent Bill To Address.Bill To Postal Code", :index =>i)

        end
        def self.same_as_billing_checkbox
            return $ie.checkbox(:id,@@form3+".ZBool_1_VP123456")
        end
    end



end